package org.atlantis.grosbeak.lang.fruit;

import java.lang.reflect.Constructor;

import org.atlantis.grosbeak.lang.Exceptions;

/**
 * 通过默认构造方法实例化对象。
 * 
 * @author <a href="mailto:seenoevil.cn@gmail.com">SeeNoEvil</a>
 * 
 */
public class DefaultConstructorFruiting<T> implements Fruiting<T> {

	private Constructor<T> c;

	/**
	 * @param c
	 *            默认构造方法。
	 */
	public DefaultConstructorFruiting(Constructor<T> c) {
		this.c = c;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.atlantis.grosbeak.lang.fruit.Fruiting#fruit(java.lang.Object[])
	 */
	public T fruit(Object[] args) {
		try {
			return c.newInstance();
		} catch (Exception e) {
			throw Exceptions
					.makeThrow(
							FruitingException.class,
							"Fail to instantiate with default constructor, because: '%s'.",
							e.getMessage());
		}
	}
}
